<template>
  <div>
    <a-modal :title="title" :visible="visible" :confirm-loading="loading" ok-text="提交" :width="900" @ok="ok" @cancel="cancel">
      <div class="about-master-container">
        <a-form-model ref="form" :model="queryParam" :rules="rules" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }" :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
          <a-row :gutter="24">
            <a-col :md="12" :sm="12">
              <a-form-model-item label="复核项目" prop="checkProjectName">
                <BaseInput v-model="queryParam.checkProjectName" disabled placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col :md="12" :sm="12">
              <a-form-model-item label="状态" prop="status">
                <a-select v-model="queryParam.status" :disabled="type === 'details'">
                  <a-select-option :value="1">可用</a-select-option>
                  <a-select-option :value="0">不可用</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="24" :sm="24">
              <a-form-model-item label="复核内容" prop="content">
                <BaseTextarea v-model="queryParam.content" :disabled="type === 'details'" :rows="4" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div  slot="footer" class="btn_box">
      <a-button type="default" @click="cancel"> 取消 </a-button>
      <a-button type="primary" v-if="type!=='details'" @click="ok"> 确定 </a-button>
    </div>
    </a-modal>
  </div>
</template>
  
  <script>
import { reviewContentContentAdd, reviewContentContentUpdate, getTeachnicalCheckContentById } from '@/api/technical/reviewContent'

export default {
  name: 'a' + Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    type: {
      type: String,
      default: ''
    },
    form: {
      type: Object,
      default: () => null
    },
    typeId: {
      type: [String, Number],
      default: null
    }
  },
  data() {
    return {
      loading: false,
      queryParam: {},
      title: '', //标题
      rules: {
        checkProjectName: [{ required: true, message: '请填写', trigger: 'blur' }],
        status: [{ required: true, message: '请选择', trigger: 'change' }],
        content: [{ required: true, message: '请填写', trigger: 'blur' }]
      }
    }
  },
  watch: {
    visible(e) {
      if (e) {
        
        if (this.type !== 'add'){
          this.getInfo()
        }else {
          console.log('this.formthis.form',this.form)
          this.queryParam.checkProjectName = this.form.name;
          this.queryParam.id = this.form.id;
        }
        switch (this.type) {
          case 'add':
            this.title = '添加复核内容'
            break
          case 'edit':
            this.title = '编辑复核内容'
            break
          case 'details':
            this.title = '查看复核内容'
            break
          default:
            this.title = '添加复核内容'
            break
        }
      } else {
        this.queryParam = {}
        this.$refs.form.clearValidate()
      }
    }
  },
  methods: {
    async getInfo() {
      let res = await getTeachnicalCheckContentById(this.form)
      if (res.data) {
        res.data.status = res.data.status ? 1 : 0
        this.queryParam = res.data
      }
    },
    async ok() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          setTimeout(() => {
            this.loading = false
          }, 3000)
          this.loading = true
          let res = ''
          console.log('paramsparams', this.queryParam)
          let params = { id: this.queryParam.checkId ? this.queryParam.id : '', checkId: this.queryParam.checkId || this.queryParam.id, content: this.queryParam.content, status: this.queryParam.status }

          if (this.queryParam.checkId) {
            res = await reviewContentContentUpdate(params)
          } else {
            delete params.id
            res = await reviewContentContentAdd(params)
          }
          this.loading = false
          this.$noticeSuccess('保存成功')
          this.$emit('ok', params)
          this.cancel()
        }
      })
    },
    cancel() {
      this.$emit('closeModal', false)
      // this.$emit('update:visible', false)
    }
  }
}
</script>
  
  <style lang="less" scoped>  /deep/.ant-input {
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
  /deep/.ant-select-selection{
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
  /deep/.ant-input[disabled] {
    border-color: #d9d9d9 !important;
    background-color: #f5f5f5 !important;
  }
  /deep/.ant-select-disabled .ant-select-selection {
    border-color: #d9d9d9 !important;
    background-color: #f5f5f5 !important;
  }

</style>
  